package com.moyoutian.daogenerate.service.impl;

import com.moyoutian.daogenerate.entity.TableEntity;
import com.moyoutian.daogenerate.entity.TableId;
import com.moyoutian.daogenerate.repository.TableRepository;
import com.moyoutian.daogenerate.service.TableService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Transactional(rollbackFor = Exception.class)
@Service
@Slf4j
@AllArgsConstructor
public class TableServiceImpl implements TableService {

    private final TableRepository repository;

    @Override
    public Page<TableEntity> findAll(TableEntity tableEntity) {
        //要匹配的实例对象
        // 定义匹配规则 匹配"vendorId"这个属性 exact 精准匹配
//        ExampleMatcher exampleMatcher = ExampleMatcher.matching().
//                withMatcher("", ExampleMatcher.GenericPropertyMatchers.exact());
//        Sort.Direction sort = Sort.Direction.ASC;
        Example<TableEntity> example = Example.of(tableEntity);
        Pageable pageable = PageRequest.of(1, 10);
        return repository.findAll(example, pageable);
    }

    @Override
    public TableEntity getOne(TableId tableId) {
        return repository.getOne(tableId);
    }


}
